<?php
/**
 * 用户红包
 * Created by PhpStorm.
 * User: poptser
 * Email: poptser@foxmail.com
 * Date: 2016/8/15
 * Time: 11:27
 */

namespace SDXApi\Model;


use Think\Model;

class UserbonusModel extends Model
{
    protected $tableName = 'user_bonus';

    /**
     * 获取红包列表
     * @param null $uid
     * @param int $current_page
     * @param int $show_all
     * @return bool
     */
    public function get_user_bonus($uid=null, $current_page=1,$show_all=1){
        if(empty($uid)) return false;
        $map = array("ub.user_id"=>$uid,"bt.bonus_type" => 0);

        $orderby = "is_use asc,is_time_out asc,can_use_time asc,min_goods_amount asc";

        $curtime = gmtime();
        if($show_all==2){   //只显示未过期的红包
            $map['_string'] = "((ub.deadline>0 and ub.deadline>=$curtime) or (ub.deadline=0 and bt.use_end_date>=$curtime))";
        }elseif($show_all==3){  //只显示过期红包
            $map['_string'] = "((ub.deadline>0 and ub.deadline<$curtime) or (ub.deadline=0 and bt.use_end_date<$curtime))";
        }

        //未使用
        elseif ($show_all == 4) {
            $map['_string'] = "ub.used_time = 0 and ((ub.deadline>0 and ub.deadline>=$curtime) or (ub.deadline=0 and bt.use_end_date>=$curtime))";
            $orderby = "type_money desc, can_use_time asc";
        }

        //已使用
        elseif ($show_all == 5) {
            $map['_string'] = "ub.used_time > 0";
            $orderby = "ub.used_time desc";
        }

        //已过期
        elseif ($show_all == 6) {
            $map['_string'] = "ub.used_time = 0 and ((ub.deadline>0 and ub.deadline<$curtime) or (ub.deadline=0 and bt.use_end_date<$curtime))";
            $orderby = "can_use_time desc";
        }

        $collect_all = $this->alias('ub')->join("left join ".C('DB_PREFIX')."bonus_type bt on ub.bonus_type_id=bt.type_id")->where($map)->count();

        if($collect_all) {
            $return_data['sumcount'] = $collect_all;
            $all_page = ceil($collect_all / C("page_size"));
            $start = ($current_page-1) *C("page_size");
            $return_data['sumcount'] = $collect_all;
            if ($all_page == $current_page) {
                //判断是否为最后一页
                $return_data['is_bottom'] = 1;
            } else {
                $return_data['is_bottom'] = 0;
            }
//             $bonus_data = $this->where(array("user_id"=>$uid))->limit($start,C("page_size"))->order("used_time desc")->select();
//             foreach ($bonus_data as $key=>$value){

//                 $bonus_type = M("bonus_type")->where('type_id='.$value['bonus_type_id'])->find();
//                 $bonus_data[$key]['type_name'] = $bonus_type['type_name'];
//                 $bonus_data[$key]['type_money'] = $bonus_type['type_money'];
//                 $bonus_data[$key]['min_amount'] = $bonus_type['min_amount'];
//                 $bonus_data[$key]['use_start_date'] = $bonus_type['use_start_date'];
//                 $bonus_data[$key]['use_end_date'] = $bonus_type['use_end_date'];
//                 $bonus_data[$key]['min_goods_amount'] = $bonus_type['min_goods_amount'];
//             }

            $bonus_data = $this->alias('ub')->field("ub.bonus_id,ub.bonus_type_id,ub.bonus_sn,ub.user_id,ub.used_time,ub.order_id,ub.emailed,ub.deadline,bt.*,if(ub.used_time>0,1,0) as is_use,if(ub.deadline>0 and ub.deadline<$curtime,1,if(ub.deadline=0 and bt.use_end_date<$curtime,1,0)) as is_time_out,if(ub.deadline>0,ub.deadline,bt.use_end_date) as can_use_time")->join("left join ".C('DB_PREFIX')."bonus_type bt on ub.bonus_type_id=bt.type_id")->where($map)->order($orderby)->limit($start,C("page_size"))->select();

            foreach ($bonus_data as $key=>$data){
                $bonus_data[$key]['use_start_date'] = localtotime($data['use_start_date']);
                if($data['deadline']>0){
                    $bonus_data[$key]['use_end_date'] = localtotime($data['deadline']);
                }else{
                    $bonus_data[$key]['use_end_date'] = localtotime($data['use_end_date']);
                }

            	if($data['is_limit_buy']==1){
            		$bonus_config = M('bonus_config')->where(array("bonus_type_id"=>$data['bonus_type_id']))->select();
            		$bonus_config_list = array();
            		foreach ($bonus_config as $cfg_key=>$cfg_data){
            			if($cfg_data['status']==0){
            				continue;
            			}
            			switch ($cfg_data['act_rang'])	{
            				case 1:
			    				$id = $cfg_data['cate_id'];
			    				$category = M('category')->field('cat_name')->where(array('cat_id'=>$id))->find();
			    				$bonus_config[$cfg_key]['typename'] = "分类";
			    				$bonus_config[$cfg_key]['name'] = $category['cat_name'];
			    			break;
			    			case 2:
			    				$id = $cfg_data['brand_id'];
			    				$brand = M('brand')->field('brand_name')->where(array('brand_id'=>$id))->find();
			    				$bonus_config[$cfg_key]['typename'] = "品牌";
			    				$bonus_config[$cfg_key]['name'] = $brand['brand_name'];
			    			break;
			    			case 3:
			    				$id = $cfg_data['goods_id'];
			    				$goods = M('goods')->field('goods_name')->where(array('goods_id'=>$id))->find();
			    				$bonus_config[$cfg_key]['typename'] = "商品";
			    				$bonus_config[$cfg_key]['name'] = $goods['goods_name'];
		    			break;
            			}
            			$bonus_config_list[] = $bonus_config[$cfg_key];
            		}
            		$bonus_data[$key]['limit_info'] = $bonus_config_list;
            	}else{
            		$bonus_data[$key]['limit_info'] = array();
            	}

                $bonus_data[$key]['place_order_start_date'] = convert_to_time($data['place_order_start_date']);
                $bonus_data[$key]['place_order_end_date'] = convert_to_time($data['place_order_end_date']);
                $bonus_data[$key]['shipping_start_date'] = convert_to_time($data['shipping_start_date']);
                $bonus_data[$key]['shipping_end_date'] = convert_to_time($data['shipping_end_date']);
                $bonus_data[$key]['shopping_type_info']='';
                switch ($data['shopping_type']){
                    case 0:
                        $bonus_data[$key]['shopping_type_info']='全场通用';
                        break;
                    case 1:
                        $bonus_data[$key]['shopping_type_info']='仅限送货到家使用';
                        break;
                    case 2:
                        $shopping_type_info='线下门店';
                        if($data['shopping_type_info']!=0){
                            $gk_sender_info=C("gk_sender_info");
                            $shopping_type_info_arr=explode(",",$data['shopping_type_info']);
                            $shopping_type_info=array();
                            foreach($shopping_type_info_arr as $item){
                                $shopping_type_info[]=$gk_sender_info[$item]['sender'];
                            }
                            $shopping_type_info=implode(",",$shopping_type_info);
                        }
                        $bonus_data[$key]['shopping_type_info']='仅限'.$shopping_type_info.'使用';
                }
            }

            $bonus_data = array_values($bonus_data);
            $return_data['list'] = $bonus_data;
            return $return_data;
        }else{
            return false;
        }
    }

    /**
     * 新加红包
     * @param null $uid
     * @param $bonus_sn
     * @return bool
     */
    public function new_user_bonus($uid=null, $bonus_sn){
        if(empty($uid)||empty($bonus_sn)){
            return false;
        }
        /* 查询红包序列号是否已经存在 */
        $row = $this->field("bonus_id, bonus_sn, user_id, bonus_type_id")->where(array('bonus_sn'=>$bonus_sn))->find();
        if ($row) {
            if ($row['user_id'] == 0) {
                //红包没有被使用
                $bonus_time = M('bonus_type')->field("send_end_date,use_end_date,has_effective_days,effective_days")->where(array("type_id"=>$row['bonus_type_id']))->find();

                $now = gmtime();
                if ($now > $bonus_time['use_end_date']) {
                    return false;   //红包过期
                }

                //如果设置了个人红包的使用有效期，则根据当前领取的时间计算红包的截止使用时间 add by yangzhic on 2016-12-13
                if($bonus_time['has_effective_days']==1 && $bonus_time['effective_days']>0){
                    $end_time = time() + ($bonus_time['effective_days']-1)*24*3600;
                    $end_date = date('Y-m-d',$end_time)." 23:59:59";
                    $deadline = local_strtotime($end_date); //转换成GMT格林威治时间戳
                }else{
                    $deadline = 0;
                }

                $bonus_data = array();
                $bonus_data['user_id'] = $uid;
                $bonus_data['get_time'] = $now;
                $bonus_data['deadline'] = $deadline;

                $result = $this->where(array("bonus_id"=>$row['bonus_id']))->save($bonus_data);
                if ($result!==false) {
                    return $this->get_honus_info($uid,$bonus_sn);
                } else {
                    return false;//更改失败
                }
            } else {
                if ($row['user_id'] == $uid) {
                    //红包已经添加过了。
                    return false;
                } else {
                    //红包被其他人使用过了。
                    return false;
                }
            }
        } else {
            //红包不存在
            return false;
        }
    }

    /**
     * 获取红包详细
     * @param null $uid
     * @param $bonus_sn
     * @return bool|mixed
     */
    public function get_honus_info($uid=null, $bonus_sn){
        if (empty($bonus_sn)) return false;

        $bonus_data = $this->where(array("user_id"=>$uid,"bonus_sn"=>$bonus_sn))->find();
        if ($bonus_data){
            return $bonus_data;
        }else{
            return false;
        }
    }

    /**
     * 通过分享邀请下单，赠送红包
     * @param $uid
     * @param $order_id
     */
    public function send_bonus_to_user($uid,$order_id){
        $share_bonus_status = M('order_info_ext')->where(array('order_id'=>$order_id))->getField('share_bonus_status');

        if(empty($share_bonus_status)){
            $share_page_info = C('SHARE_PAGE_INFO');
            $map = array('is_first_login'=>1,'uid'=>$uid,'share_uid'=>array('neq',0));

            $share_info = D('user_behavior_address')->where($map)->find();
            if(!empty($share_info) && !empty($share_page_info['bonus_id'])){
                $order_map = array(
                    'user_id'=>$uid,
                    'order_status'=>array("in","1,5"),
                    'shipping_status'=>2,
                    'pay_status'=>array("in","2,3"),
                    'order_id'=>array('neq',$order_id)
                );

                $order_count = D('order_info')->where($order_map)->count();
                if($share_page_info['give_type']==1 && $order_count>0){
                    return false;
                }

                //赠送红包
                $send_res = $this->auto_get_bonus($share_page_info['bonus_id'],$uid,1);
                $this->add_share_user_bonus($share_info,$send_res);

                //赠送推荐人红包
                if(!empty($share_info['share_uid']) && $send_res['error']==0){
                    $send_share_res = $this->auto_get_bonus($share_page_info['bonus_id'],$share_info['share_uid'],1);
                    $this->add_share_user_bonus($share_info,$send_share_res);
                }

                if((!empty($send_res) && $send_res['error']==0) || (!empty($send_share_res) && $send_share_res['error']==0)){
                    $map_ext = array('order_id'=>$order_id);
                    $order_info_ext = M('order_info_ext')->where($map_ext)->find();
                    if(empty($order_info_ext)){
                        $data_ext = array('order_id'=>$order_id,'share_bonus_status'=>1);
                        M('order_info_ext')->add($data_ext);
                    }else{
                        M('order_info_ext')->where($map_ext)->setField('share_bonus_status',1);
                    }

                    $this->send_sms_share_bonus_notice($share_info,$send_res,$send_share_res);
                }
            }
        }
    }

    /**
     * 双12首单送红包
     * @param $user_id
     * @param $order_id
     * @return bool
     */
    public function send_bonus_for_d12($user_id,$order_id){
        $d12_config = C('d12_config');
        $start_time = $d12_config['start_time'];
        $end_time= $d12_config['end_time'];

        //初始化时区，解决时区不正确的问题
        date_default_timezone_set('PRC');

        $current_time = time();
        if($current_time<$start_time || $current_time>$end_time){
            return false;
        }

        $order_map = array(
            'user_id'=>$user_id,
            'order_status'=>array("gt",0),
            'pay_status'=>array("in","2,3,4"),
            'pay_time'=>array(array('egt',($start_time-8*3600)),array('elt',($end_time-8*3600)))
        );

        $order_info = M('order_info')->where($order_map)->order(array('pay_time'=>'asc'))->find();

        if($order_info['order_id']==$order_id){
            $res = $this->auto_get_bonus($d12_config['bonus_id'],$user_id);

            if(!empty($res) && $res['error']==0){
                $user_info = D('users')
                    ->alias('u')
                    ->field('wu.nickname,u.mobile_phone,u.reg_time')
                    ->join('left join '.C('DB_PREFIX').'wechat_user wu on u.user_id=wu.ect_uid')
                    ->where(array('u.user_id'=>$user_id))
                    ->find();

                if(!empty($res['bonus_info_list']) && !empty($res['bonus_id'])){
                    $bonus_info = $this->get_bonus_info($res);
                    $wechat_param=array();
                    $wechat_param['url']="https://w.shidexian.com/?index=/bag";
                    $wechat_param['keyword1']=$user_info['nickname'];
                    $wechat_param['keyword2']=$bonus_info['bonus_name'];
                    $wechat_param['keyword3']= '红包到期时间（'.$bonus_info['bonus_end_date'].'）';
                    $notice_type = "d12_bonus_notice";
                    $remark = array('bonus_title'=>$d12_config['bonus_title'],'bonus_ad'=>$d12_config['bonus_ad']);
                    A("Smsapi")->send_message_api($notice_type,$user_info['mobile_phone'],$user_info['nickname'],0,0,0,$user_id,$remark,null,$wechat_param);
                }
            }
        }
        return true;
    }

    /**
     * 双12当天取消订单回收红包
     * @param $user_id
     * @param $order_id
     * @return bool
     */
    public function cancel_bonus_for_d12($user_id,$order_id){
        $d12_config = C('d12_config');
        $start_time = $d12_config['start_time'];
        $end_time= $d12_config['end_time'];

        //初始化时区，解决时区不正确的问题
        date_default_timezone_set('PRC');

        $current_time = time();
        if($current_time<$start_time || $current_time>$end_time){
            return false;
        }

        $order_map = array(
            'user_id'=>$user_id,
            'order_status'=>array("gt",0),
            'pay_status'=>array("in","2,3,4"),
            'pay_time'=>array(array('egt',($start_time-8*3600)),array('elt',($end_time-8*3600)))
        );

        $order_info = M('order_info')->where($order_map)->order(array('pay_time'=>'asc'))->find();

        if($order_info['order_id']==$order_id){
            if(!empty($d12_config['bonus_id'])){
                $bonus_id = explode(',',$d12_config['bonus_id']);

                $map = array("bonus_type_id"=>array('in',$bonus_id),"user_id"=>$user_id,'used_time'=>0);
                $user_bonus_data = M("user_bonus")->where($map)->find();
                if(!empty($user_bonus_data)){
                    $data = array();
                    $data['user_id'] = 0;
                    $data['get_time'] = 0;
                    $data['deadline'] = 0;
                    M("user_bonus")->where($map)->save($data);
                }
            }
        }

        return true;
    }


    /**
     * 保存分享邀请获赠红包信息
     * @param $share_info
     * @param $send_share_res
     */
    public function add_share_user_bonus($share_info,$send_share_res){
        if(!empty($send_share_res) && $send_share_res['error']==0){
            $share_user_bonus_data = array();

            $bonus_list = $this->get_user_bonus_list($send_share_res['bonus_id']);
            $share_user_bonus_data['uba_id'] = $share_info['id'];
            $share_user_bonus_data['create_time'] = gmtime();
            if(!empty($bonus_list)){
                foreach($bonus_list as $key=>$bonus){
                    $share_user_bonus_data['uid'] = $bonus['user_id'];
                    $share_user_bonus_data['bonus_id'] = $bonus['bonus_id'];
                    $share_user_bonus_data['bonus_sn'] = $bonus['bonus_sn'];
                    M('user_share_bonus')->add($share_user_bonus_data);
                }
            }
        }
    }

    public function get_user_bonus_list($bonus_id){
        $bonus_ids = explode(',',$bonus_id);
        $map = array('bonus_id'=>array('in',$bonus_ids));
        $bonus_sn_list = M('user_bonus')->where($map)->select();

        return $bonus_sn_list;
    }


    public function send_sms_share_bonus_notice($share_info,$send_share_Invited_user_res,$send_share_Inviter_res){
        $share_page_info = C('SHARE_PAGE_INFO');
        if(!empty($send_share_Invited_user_res) && $send_share_Invited_user_res['error']==0){
            $user_info = D('users')
                ->alias('u')
                ->field('wu.nickname,u.mobile_phone,u.reg_time')
                ->join('left join '.C('DB_PREFIX').'wechat_user wu on u.user_id=wu.ect_uid')
                ->where(array('u.user_id'=>$share_info['uid']))
                ->find();
            if(!empty($send_share_Invited_user_res['bonus_info_list']) && !empty($send_share_Invited_user_res['bonus_id'])){
                $invited_bons_info = $this->get_bonus_info($send_share_Invited_user_res);
                $wechat_param=array();
                $wechat_param['url']="https://w.shidexian.com/?index=/bag";
                $wechat_param['keyword1']=$user_info['nickname'];
                $wechat_param['keyword2']=$invited_bons_info['bonus_name'];
                $wechat_param['keyword3']= '截止至（'.$invited_bons_info['bonus_end_date'].'）';
                $notice_type = "share_invited_bonus_arrived";
                $remark = array('bonus_name'=>$invited_bons_info['bonus_name'],'bonus_ad'=>$share_page_info['bonus_ad']);
                A("Smsapi")->send_message_api($notice_type,$user_info['mobile_phone'],$user_info['nickname'],0,0,0,$share_info['uid'],$remark,null,$wechat_param);
            }

        }

        if(!empty($send_share_Inviter_res) && $send_share_Inviter_res['error']==0){
            $share_user_info = D('users')
                ->alias('u')
                ->field('wu.nickname,u.mobile_phone,u.reg_time')
                ->join('left join '.C('DB_PREFIX').'wechat_user wu on u.user_id=wu.ect_uid')
                ->where(array('u.user_id'=>$share_info['share_uid']))
                ->find();
            $wechat_param=array();
            $wechat_param['url']="https://w.shidexian.com/?index=/bag";
            $wechat_param['keyword1']=$user_info['nickname'];
            $wechat_param['keyword2']="食得鲜";
            $wechat_param['keyword3']= local_date("Y-m-d H:i:s",$user_info['reg_time']);
            $notice_type = "share_inviter_bonus_notice";

            $remark = array('invited_nickname'=>$user_info['nickname']);
            A("Smsapi")->send_message_api($notice_type,$share_user_info['mobile_phone'],$share_user_info['nickname'],0,0,0,$share_info['share_uid'],$remark,null,$wechat_param);
        }


    }


    public function get_bonus_info($Invited_user_bonus_info){
        $bonus_name = '';
        $bonus_end_date = '';
        if(!empty($Invited_user_bonus_info['bonus_id'])){
            $bonus_iss = explode(',',$Invited_user_bonus_info['bonus_id']);
        }
        $user_bonus_list = M('user_bonus')->where(array('bonus_id'=>array('in',$bonus_iss)))->select();
        foreach($Invited_user_bonus_info['bonus_info_list'] as $key=>$bonus_data){
            $user_bonus = array();
            foreach($user_bonus_list as $ub_key=>$u_bonus){
                if($u_bonus['bonus_type_id']==$bonus_data['type_id']){
                    $user_bonus = $u_bonus;
                    break;
                }
            }

            if($bonus_data['bonus_discount_type']==1){
                $discount_name= '满'.$bonus_data['min_goods_amount'].'元减'.$bonus_data['type_money'].'元红包';
            }else{
                $discount_name= $bonus_data['type_money'].'折红包';
            }

            if(empty($bonus_name)){
                $bonus_name.=$discount_name;
            }else{
                $bonus_name.=' / '.$discount_name;
            }


            //获取红包使用截止时间
            if($user_bonus['deadline']>0){
                $use_end_date = local_date('Y-m-d H:i',$user_bonus['deadline']);
            }else{
                $use_end_date = local_date('Y-m-d H:i',$u_bonus['use_end_date']);
            }

            if(empty($bonus_end_date)){
                $bonus_end_date.=$use_end_date;
            }else{
                $bonus_end_date.=' / '.$use_end_date;
            }
        }

        $res = array();
        $res['bonus_name'] = $bonus_name;
        $res['bonus_end_date'] = $bonus_end_date;
        return $res;
    }
    /**
     * 自动领取指定类型红包
     * @param null $bonus_type_id
     * @param $uid
     * @param $is_share_user
     * @return array
     */
    public function auto_get_bonus($bonus_type_id = null,$uid,$is_share_user=0){
        $return_data = array('error'=>1);
        if(S("auto_get_bonus_".$uid)>0){
            $return_data['msg'] = "领取中";
            return $return_data;
        }else{
            S("auto_get_bonus_".$uid,999,10);
        }
        if(empty($bonus_type_id)){
            $bonus_type_id = I("post.bonus_type_id");
        }


        if(!is_numeric($bonus_type_id)){
            //处理一次领取多个红包的问题
            $bonus_type_array =  explode(",",$bonus_type_id);
        }else{
            $bonus_type_array = array();
            $bonus_type_array[] = $bonus_type_id;
        }

        if(empty($bonus_type_array)){
            $return_data['msg'] = "参数错误:无指定红包类型ID";
            return $return_data;
        }
        $user_bonus = 0;

        $map = array("send_type"=>3,"type_id"=>array('in',$bonus_type_array));
        $bonus_list = M("bonus_type")->where($map)->select();
        if(empty($bonus_list)){
            $return_data['msg'] = "当前没有可领取的红包";
            return $return_data;
        }
        if(!$is_share_user){
            foreach ($bonus_list as $key=>$value){
                $user_bonus_data = M("user_bonus")->where(array("bonus_type_id"=>$value['type_id'],"user_id"=>$uid))->find();
                if($user_bonus_data){
                    unset($bonus_list[$key]);
                    $user_bonus ++;
                }
            }

            if(count($bonus_list)==0){
                $return_data['action'] = 1;
                $return_data['error']=1;
                $return_data['msg'] = "已经领取此红包";
                return $return_data;
            }
        }

        //初始化时区，解决时区不正确的问题
        date_default_timezone_set('PRC');
        $bonus_array = array();
        foreach ($bonus_list as $key=>$value){
            //            $bonus_data = M("bonus_type")->where(array("send_type"=>3,"type_id"=>$value))->find();
            $bonus_data = $value;
//            $res = $this->check_bouns_rank($uid,$bonus_data);
//            if(!$res){
//                if($bonus_data['bouns_user_rank']==2){
//                    //returnApiError("VIP专享福利，这就是传说中的V..V..V..VIP 专享福利咯");
//                    $return_data['msg'] = "该红包仅限 VIP 领取";
//                    return $return_data;
//                }
//                if($bonus_data['bouns_user_rank']==1){
//                    //returnApiError("注册用户专享福利，您已经够强大，无需此光环啦");
//                    $return_data['msg'] = "该红包仅限 注册用户 领取";
//                    return $return_data;
//                }
//                if($bonus_data['bouns_user_rank']==100){
//                    //returnApiError("新人入门礼包，是送给刚来小朋友的，不要抢哦！");
//                    $return_data['msg'] = "该红包仅限 新用户 领取";
//                    return $return_data;
//                }
//            }

            if($bonus_data['has_effective_days']==1 && $bonus_data['effective_days']>0){
                $end_time = time() + ($bonus_data['effective_days']-1)*24*3600;
                $end_date = date('Y-m-d',$end_time)." 23:59:59";
                $deadline = local_strtotime($end_date); //转换成GMT格林威治时间戳
            }else{
                $deadline = 0;
            }


            $bonus_id_f = M("user_bonus")->where(array("bonus_type_id"=>$bonus_data['type_id'],"user_id"=>0))
                ->getField("bonus_id");

            if($bonus_id_f){
                $data['user_id'] = $uid;
                $data['get_time'] = gmtime();
                $data['deadline'] = $deadline;
                M("user_bonus")->where(array("bonus_id"=>$bonus_id_f))->save($data);
                $bonus_array[] = $bonus_id_f;
                $bonus_info_list[] = $bonus_data;
            }else{
                $return_data['msg'] = "来晚一步，红包发完了";
                return $return_data;
            }
        }

        $return_data['action'] = 1;
        $return_data['bonus_id'] = implode(",",$bonus_array);
        $return_data['bonus_info_list'] = $bonus_info_list;
        $return_data['msg'] = "领取成功";
        $return_data['error']=0;
        return $return_data;
    }

    public function getBonusTotalNumber($bonusTypeId){
        $map = array('bonus_type_id'=>$bonusTypeId);
        return $this->where($map)->count('bonus_id');
    }

}